package com.szzg10.thinking.chapter11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Set;

public class PriorityQueueDemo {

	public static void main(String[] args) {
		Random random = new Random(47);
		
		PriorityQueue<Integer> priorityQueue = new PriorityQueue<Integer>();
		for(int i = 0; i < 10; i++) {
			priorityQueue.offer(random.nextInt(i + 10));
		}
		QueueDemo.printQ(priorityQueue);
		
		List<Integer> listInteger = Arrays.asList(25, 22, 20, 18, 14, 9, 3, 1, 1, 1, 2, 3, 9, 14, 18, 21, 23, 25);
		priorityQueue = new PriorityQueue<Integer>(listInteger);
		QueueDemo.printQ(priorityQueue);
		
		priorityQueue = new PriorityQueue<Integer>(listInteger.size(), Collections.reverseOrder());
		priorityQueue.addAll(listInteger);
		QueueDemo.printQ(priorityQueue);
		
		String fact = "EDUCATION SHOULD ESCHEW OBFUSCATION";
		List<String> listString = Arrays.asList(fact.split(""));
		PriorityQueue<String> priorityQueue2 = new PriorityQueue<String>(listString);
		QueueDemo.printQ(priorityQueue2);
		
		priorityQueue2 = new PriorityQueue<String>(listString.size(), Collections.reverseOrder());
		priorityQueue2.addAll(listString);
		QueueDemo.printQ(priorityQueue2);
		
		Set<Character> set = new HashSet<Character>();
		for(Character character: fact.toCharArray()) {
			set.add(character);
		}
		PriorityQueue<Character> priorityQueue3 = new PriorityQueue<Character>(set);
		QueueDemo.printQ(priorityQueue3);
	}
}
